#!/bin/env ruby
# encoding: utf-8

### login from http://mutualforce.7bits.it/homeAbout.html
### login from https://mutualforce.7bits.it/Red_Klin/home.html
###
###
###
def sign_in (usernameM, userpasswordM)
  goto 'http://mutualforce.7bits.it/homeAbout.html'
  a(id: "js-login", class: "b-quick-access__button_link", href: "loginDialog.html", text: "Login!").click 
  text_field(name: "j_username").set usernameM
  text_field(name: "j_password").set userpasswordM
  form(name: "login_form") 
        .table[0][1]
        .button(name: "submit", value: "Sign In", class: "b-button b-sign-in__new_input_submit").click   
  STDERR.puts "*** in system "
  #a(class: "b-button b-user-menu__link js-b-user-menu__login-link").click
  #a(class: "b-user-menu__list-link", href: "j_spring_security_logout", text: "Log out").wait_until_present(5)
  #a(class: "b-user-menu__list-link", href: "userProfile.html", text: "Profile").wait_until_present(5)        
end



def sign_in_homepage (usernameM, userpasswordM, nameM)
  goto  'https://mutualforce.7bits.it/' + nameM + '/home.html'
  text_field(name: 'j_username').wait_until_present
  text_field(name: 'j_username').set usernameM
  text_field(name: 'j_password').set userpasswordM
  button(class: "b-button b-sign-in__input_submit b-sign-in__link-float", value: "Sign In", name: "submit").click
  #a(class: "b-button b-user-menu__link js-b-user-menu__login-link").click
  #a(class: "b-user-menu__list-link", href: "j_spring_security_logout", text: "Log out").wait_until_present(5)
  #a(class: "b-user-menu__list-link", href: "userProfile.html", text: "Profile").wait_until_present(7)                             
 

end

def user_logout
  a(class: "b-button b-user-menu__link js-b-user-menu__login-link").click
  a(href: "j_spring_security_logout", class: "b-user-menu__list-link", text: "Log out").wait_until_present(10)
  a(href: "j_spring_security_logout", class: "b-user-menu__list-link", text: "Log out").click
end


